<?php

if(!isset($_SESSION['username'])){
		echo "<script>alert('请登录！');window.location.href='index.php?m=admin&c=manage'</script>";die;
	}
	
	
	//权限管理
	authonity($con);


	$id = $_GET['id'];

	$aid = $_GET['aid'];
	
	$mid = $_GET['mid'];

	


	//添加权限角色时的权限多选框无极分类:
	$auth = dbselect($con,'authonity','*','id<>1');

	$authc = child($auth);

	assign('authc',$authc);

	//用GET到的id查找到相应的权限角色：

	$cur_permiss = dbselOne($con,'permission','*',$id);

	assign('cur_permiss',$cur_permiss);

	//GET到的id下的权限角色拥有的权限id数组
	$auth_id_upd = explode(',',$cur_permiss['auth_id']);

	assign('auth_id_upd',$auth_id_upd);

	if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])=='xmlhttprequest'){


		if(isset($_POST['auth'])){

			//判断权限角色的唯一性
			$bper = htmlspecialchars(trim($_POST['auth']));

			$query = dbselect($con,'permission','per_name,id',"per_name='{$bper}' and id<>'{$id}'");

			if($query){
				echo 1 ;die;
			}else{
				echo 0 ;die;
			}

		}else if(isset($_POST['submit'])){

			//提交修改权限角色信息
			$filed['per_name'] =  htmlspecialchars(trim($_POST['per_na']));

			$filed['auth_id'] = $_POST['checks'] ; 

			// dbupdate($con,$table,$field,$where=null)
			$query = dbupdate($con,'permission',$filed ,"id='{$id}'");

			if($query){
				echo 1;die;
			}else{
				echo 0;die;
			}
		}else if(isset($_POST['caut_id'])){
			$caut_id = $_POST['caut_id'];

			$query = dbselect($con,'authonity','id',"pid='{$caut_id}'");

			echo json_encode($query);die;
		}
		


	}



?>